//
//  XHFirstTypeThreeCell.m
//  umibus
//
//  Created by fengyn on 16/6/18.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHFirstTypeThreeCell.h"

@implementation XHFirstTypeThreeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.ui_buttonBorderView.layer.borderColor=[ColorManager colorWithHexString:@"#666666"].CGColor;
    self.ui_buttonBorderView.layer.borderWidth=0.5;
    self.ui_jiaButton.layer.borderColor=[ColorManager colorWithHexString:@"#666666"].CGColor;
    self.ui_jiaButton.layer.borderWidth=0.5;
    self.ui_jianButton.layer.borderColor=[ColorManager colorWithHexString:@"#666666"].CGColor;
    self.ui_jianButton.layer.borderWidth=0.5;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setData:(NSArray *)dataArray
{
    self.m_dataArray=dataArray;
    if (dataArray.count>0) {
        if (self.m_selectedIndex>=dataArray.count) {
            self.m_selectedIndex=dataArray.count-1;
        }
        NSDictionary *dic=dataArray[self.m_selectedIndex];
        self.ui_valueLabel.text=[dic[@"productValue"] stringValue];
        double value=[dic[@"productValue"] doubleValue]*self.m_packageCount;
        self.ui_detailLabel.text=[NSString stringWithFormat:@"%ld个月共充值%.2f元",self.m_packageCount,value];
    }
}

- (IBAction)jianButtonAction:(id)sender {
    self.m_selectedIndex--;
    self.m_selectedIndex=self.m_selectedIndex+self.m_dataArray.count;
    self.m_selectedIndex=(self.m_selectedIndex)%self.m_dataArray.count;
    NSDictionary *dic=self.m_dataArray[self.m_selectedIndex];
    self.ui_valueLabel.text=[dic[@"productValue"] stringValue];
    double value=[dic[@"productValue"] doubleValue]*self.m_packageCount;
    self.ui_detailLabel.text=[NSString stringWithFormat:@"%ld个月共充值%.2f元",self.m_packageCount,value];
    if ([self.delegate respondsToSelector:@selector(valueDidChange:index:)]) {
        [self.delegate valueDidChange:dic index:self.m_selectedIndex];
    }
}

- (IBAction)jiaButtonAction:(id)sender {
    self.m_selectedIndex++;
    self.m_selectedIndex=self.m_selectedIndex%self.m_dataArray.count;
    NSDictionary *dic=self.m_dataArray[self.m_selectedIndex];
    self.ui_valueLabel.text=[dic[@"productValue"] stringValue];
    double value=[dic[@"productValue"] doubleValue]*self.m_packageCount;
    self.ui_detailLabel.text=[NSString stringWithFormat:@"%ld个月共充值%.2f元",self.m_packageCount,value];
    if ([self.delegate respondsToSelector:@selector(valueDidChange:index:)]) {
        [self.delegate valueDidChange:dic index:self.m_selectedIndex];
    }
}
@end
